from django.db import models

# Create your models here.
"""
on_delete参数

CASECADE 级联删除
PROTECT，article不删除数据，User不能删除数据
SET_NULL  USER数据删除，Article.author设置为NULL，前提是NULL=TRUE
SET_DEFAULT()  设置默认值，需要设置default
SET() 可以设置一个方法
DO_NOTHING 啥都不做，按照数据库层面来做

"""
#一对多
class User(models.Model):
    username = models.CharField(max_length = 20)
    password = models.TextField(max_length = 100)

class Article(models.Model):
    title = models.CharField(max_length = 100)
    content = models.TextField()

    author = models.ForeignKey(User, on_delete = models.CASCADE,related_name='articles')


# #一对一
# class User(models.Model):
#     username = models.CharField(max_length = 20)
#     password = models.TextField(max_length = 100)
#
# class UserExtension(models.Model):
#     birth_date = models.DateTimeField(null=True)
#     school = models.CharField(max_length = 20,blank=True)
#     user = models.OneToOneField(User,on_delete=models.CASCADE)


#多对多
class Tags(models.Model):
    name = models.CharField(max_length=100)

class Article_tag(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()
    tags = models.ManyToManyField(Tags,related_name='articles')